﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Controls
{
    public partial class BoxChangePass : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Username"] == null)
            {
                Response.Redirect("/home");
            }
        }

        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            string passold = txtPassOld.Text;
            string sessionpass = Session["Password"].ToString();
            if (!passold.Equals(sessionpass))
            {
                lblCheckPassOld.Text = "Mật khẩu cũ không đúng";

            }
            else
            {
                string newpass = LIB.Converter.Encode("sha1", txtNewPass.Text);
                DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[1];
                cl[0] = new DAL.DHelpers.Column("Employee_Password", newpass, DAL.DHelpers.DataType.DataTypeSql.Varchar);
                string[] colWhere = new string[1];
                colWhere[0] = "Employee_User";

                object[] colValue = new object[1];
                colValue[0] = newpass;
                DAL.DCollector.DBCollector.Instance.StoredProcedureUpdateByRow("tbl_Employee", "Employee_User", Session["Username"].ToString(), "Employee_Password", newpass);
                Response.Redirect("/home");
            }
        }
    }
}